/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package net.huangp.framework;

import java.util.List;
import org.hibernate.Query;

/**
 * TODO not in use
 * @author Patrick Huang
 */
public class HibernatePage {
    //--------------------------------------------------------------------------
    // Static Properties
    //--------------------------------------------------------------------------

    //--------------------------------------------------------------------------
    // Properties
    //--------------------------------------------------------------------------
    private List results;
    private int pageSize;
    private int page;

    // -------------------------------------------------------------------------
    // Implementation Methods
    // -------------------------------------------------------------------------
    public HibernatePage(Query query, int page, int pageSize) {
        this.page = page;
        this.pageSize = pageSize;
        results = query.setFirstResult(page * pageSize).setMaxResults(pageSize + 1).list();

    }
    public boolean isNextPage() {
        return results.size() > pageSize;
    }

    public boolean isPreviousPage() {
        return page > 0;
    }

    public List getList() {
        return isNextPage() ? results.subList(0, pageSize - 1) : results;
    }

    // -------------------------------------------------------------------------
    // Mutator Methods
    // -------------------------------------------------------------------------
}
